package demo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-07-29
 * Time: 12:29
 */
public class demoCard {
    public static final String[] suits={"♥","♠","♣","♦"};

    //1.买牌   2.洗牌   3.玩牌
    //1.买牌
    public List<Card> buyCard(){
        List<Card> CardList=new ArrayList<>();
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < suits.length; j++) {
                String suit=suits[j];
                int rank=i;
                Card card=new Card(suit,rank);
                CardList.add(card);
            }
        }
        return CardList;
    }

    //2.洗牌
    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size()-1; i > 0 ; i--) {
            int index = random.nextInt(i);//随机生成一个[0,i)的数字
            swap(cardList,i,index);
        }
    }

    private void swap(List<Card> cardList,int i,int j) {
        /*
        Card tmp =  cardList[i];
        cardList[i] = cardList[j];
        cardList[j] = tmp;
         */
        Card tmp=cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,tmp);
    }

    //3.玩牌
    public void play(List<Card> cardList){
        List<Card> hand0=new ArrayList<>();
        List<Card> hand1=new ArrayList<>();
        List<Card> hand2=new ArrayList<>();

        List<List<Card>> players=new ArrayList<>();
        players.add(hand0);
        players.add(hand1);
        players.add(hand2);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card=cardList.remove(0);//每次都拿最上面的牌
                players.get(j).add(card);
            }
        }

        for (int i = 0; i < players.size(); i++) {
            for (int j = 0; j < players.get(i).size(); j++) {
                System.out.print("第"+i+"个玩家的牌是:"+players.get(i).get(j));
            }
            System.out.println();
        }
    }

}





















